package com.tza.web.t_net.server.screenservices.blockservices;

import java.util.ArrayList;
import java.util.List;

import com.tza.web.t_net.client.screenservices.DataProviderService;
import com.tza.web.t_net.server.screenservices.BeanWithId;
import com.tza.web.t_net.shared.entity.DataMap;

public class DataProviderServiceImpl implements BeanWithId, DataProviderService
{

   public static final String BEANID = "DataProviderService";

   public DataMap getData(DataMap inParameters, String beanId)
   {

      return null;

   }

   public List<DataMap> getGridData(String service, DataMap criteria)
   {

      if ("Test".equals(service))
      {

         return buildTestRecordList();
      }
      else
         return null;
   }

   private DataMap buildTestRecord(int index)
   {
      DataMap record = new DataMap();
      record.put("countryCode", "216" + index);
      record.put("countryName", "Bol " + index);
      record.put("countryPopulation", "salaire" + index);
      record.put("name", "Name" + index);
      return record;
   }

   private List<DataMap> buildTestRecordList()
   {
      List<DataMap> gridData = new ArrayList<DataMap>();

      gridData.add(buildTestRecord(1));
      gridData.add(buildTestRecord(2));
      gridData.add(buildTestRecord(3));
      gridData.add(buildTestRecord(4));
      gridData.add(buildTestRecord(5));
      return gridData;
   }

   private DataMap buildTestTreeRecord(int index)
   {
      DataMap root = buildTestRecord(1);
      DataMap recordF1 = buildTestRecord(2);
      DataMap recordF2 = buildTestRecord(3);

      DataMap recordF21 = buildTestRecord(4);
      DataMap recordF22 = buildTestRecord(5);

      recordF2.put("recordF21", recordF21);
      recordF2.put("recordF22", recordF22);

      root.put("recordF1", recordF1);
      root.put("recordF2", recordF2);

      return root;
   }

   public String getBeanId()
   {
      return BEANID;
   }

   public DataMap getTreeGridData(String gridService, DataMap criteria)
   {

      return buildTestTreeRecord(1);
   }
}
